package task;

import java.util.Arrays;

public class Task6_9 {
    public static int binarySort(int key,int[] array){
        int left = 0;
        int right = array.length - 1;
        while(left <= right) {
            int mid = right + left >> 1;
            if(array[mid] < key){
                left = mid + 1;
            }else if(array[mid] > key){
                right = mid - 1;
            }else{
                return mid;
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,7};
        //System.out.println(Arrays.binarySearch(array, 2));
        System.out.println(binarySort(2, array));
    }
}
